﻿@model yq.IBase.Table.TableInfo
@{
    Layout = null;
}
DROP Trigger trigger_@(Model.Code)_update;
DROP Trigger trigger_@(Model.Code)_delete;

Create  Trigger [trigger_@(Model.Code)_update] AFTER UPDATE On [@(Model.Code)] FOR EACH ROW
begin

      Update @(Model.Code) Set Version=strftime('%s',"now")  Where @(Model.Columns[0].Code)=Old.@(Model.Columns[0].Code) and old.Version=new.Version;       
        
  
INSERT INTO CaChe_UpdateLog
           (CaCheId
           ,KeyValue
           ,TableName
           ,Status
           ,Type
           ,CreateTime)
    -- VALUES(Old.@(Model.Columns[0].Code)||strftime('%s',"now"),Old.@(Model.Columns[0].Code),'@(Model.Code)',0,0,datetime('now', 'localtime')) 
     SELECT old.@(Model.Columns[0].Code)||strftime('%s',"now"),Old.@(Model.Columns[0].Code),'@(Model.Code)',0,0,datetime('now', 'localtime')
WHERE Old.Version=new.Version ;
       
     
end;

Create  Trigger [trigger_@(Model.Code)_delete] BEFORE DELETE On [@(Model.Code)] FOR EACH ROW
begin
INSERT INTO CaChe_UpdateLog
           (CaCheId
           ,KeyValue
           ,TableName
           ,Status
           ,Type
           ,CreateTime)
     VALUES(OLD.@(Model.Columns[0].Code),OLD.@(Model.Columns[0].Code),"@(Model.Code)",0,1,datetime('now', 'localtime'));
end;
